package com.zy.scworder.controller;

import com.zy.scwcommon.bean.AppResponse;
import com.zy.scworder.bean.TOrder;
import com.zy.scworder.service.TOrderService;
import com.zy.scworder.vo.req.OrderInfoSubmitVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @program: zyzc_springcloud
*
* @description: 订单表接口
*
* @author: ZYY
*
* @create: 2024-07-19 11:32
**/
@RestController
@Slf4j
@RequestMapping("/order")
public class OrderController {
	@Autowired
	TOrderService tOrderService;
	@RequestMapping("/pay")
	public String pay( ){

		return null;
	}
	/**
	 * @Description:
	 * @Param:
	 * @return:
	 * @Author: zy
	 * @Date:
	 */
	@PostMapping("/saveOrder")
	public AppResponse<TOrder> saveOrder(@RequestBody OrderInfoSubmitVo submitVo){

		try {
			//为了防止重复保存需要在配置文件设置ribbon的重复机制为0（在weiuis上配置）
			TOrder tOrder = tOrderService.saveOrder(submitVo);
			AppResponse<TOrder> resp = AppResponse.ok(tOrder);
			return resp;
		} catch (Exception e) {
			e.printStackTrace();
			AppResponse<TOrder> res = AppResponse.fail(null);
			res.setMsg("保存订单----数据失败");
			log.error("保存订单----数据失败");
			return res;
		}
	}
}
